package ca.usherbrooke.builder.equipment;

import java.io.FileNotFoundException;
import java.io.IOException;

import ca.usherbrooke.view.properties.PropertieBase;

public class EquipmentModelObjectBuilder {

	private final static String TYPE = "equipment_model_type_key";
	private final static String TYPE_WEAPON = "weapon";
	private final static String TYPE_PROTECTION = "protection";

	// name keys
	private final static String NAME = "equipment_model_name_key";

	// position key
	private final static String POSITION_X = "position_x_key";
	private final static String POSITION_Y = "position_Y_key";
	private final static String POSITION_WIDTH = "position_width_key";
	private final static String POSITION_HEIGHT = "position_height_key";
	private final static String CAPACITY = "capacity_key";

	public static EquipmentModelObject createEntityObject(String fileName)
			throws FileNotFoundException, IOException {
		PropertieBase properties = new PropertieBase(fileName);

		String type = properties.getValue(TYPE);

		EquipmentModelObject equipmentObject = new EquipmentModelObject();

		if (TYPE_WEAPON.equals(type)) {
			equipmentObject = WeaponModelObjectBuilder
					.createWeaponObject(fileName);
		} else if (TYPE_PROTECTION.equals(type)) {
			equipmentObject = ProtectionModelObjectBuilder
					.createProtectionObject(fileName);
		} else {
			fillEquipmentObject(properties, equipmentObject);
		}

		return equipmentObject;
	}

	public static void fillEquipmentObject(PropertieBase properties,
			EquipmentModelObject equipmentObject) {

		// entity name
		equipmentObject.name = properties
				.getValue(EquipmentModelObjectBuilder.NAME);

		// entity position
		equipmentObject.positionX = properties
				.getFloatValue(EquipmentModelObjectBuilder.POSITION_X);
		equipmentObject.positionY = properties
				.getFloatValue(EquipmentModelObjectBuilder.POSITION_Y);
		equipmentObject.positionWidth = properties
				.getFloatValue(EquipmentModelObjectBuilder.POSITION_WIDTH);
		equipmentObject.positionHeight = properties
				.getFloatValue(EquipmentModelObjectBuilder.POSITION_HEIGHT);

		equipmentObject.capacity = properties
				.getIntegerValue(EquipmentModelObjectBuilder.CAPACITY);
	}
}
